package com.globaldom.utils;

import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public final class SessionManager {

	public static final String getID(HttpServletRequest request,HttpSession session )
	{
		String personID = (String) session.getAttribute("personID");	
		if (null == personID) {

			Cookie[] cookies = request.getCookies();
			if(null==cookies) return null;
			
			for (int i = 0; i < cookies.length; i++) {
				Cookie cookie = cookies[i];
				if ((cookie.getName().equals("a"))) {
					String id = cookie.getValue();
					Map<String, Object> m = MemCacheManager.getAuthStats(id);
					if (null != m) {
						personID = (String) m.get("personID");
						session.setAttribute("personID", personID);
					} else {
						return null;

					}
				}

			}

		}
		return personID;
	}
}
